package com.opengate.base.asserts;

import com.opengate.base.exception.OpenGateException;
import org.apache.commons.lang3.StringUtils;

/**
 * @author 曳戈泰尔
 * @version 1.0
 * @description 断言辅助类
 * @date 2023/4/26 5:46 PM
 */
public class AssertHelper {

    public static void isNull(Object obj, int code, String message) {
        if (null != obj) {
            throw new OpenGateException(code, message);
        }
    }

    public static void notNull(Object obj, int code, String message) {
        if (obj == null) {
            throw new OpenGateException(code, message);
        }
    }

    public static void isFalse(boolean expression, int code, String message) {
        if (expression) {
            throw new OpenGateException(code, message);
        }
    }

    public static void isTrue(boolean expression, int code, String message) {
        if (!expression) {
            throw new OpenGateException(code, message);
        }
    }

    public static void isEmpty(String expression, int code, String message) {
        if (StringUtils.isNotEmpty(expression)) {
            throw new OpenGateException(code, message);
        }
    }

    public static void notEmpty(String expression, int code, String message) {
        if (StringUtils.isEmpty(expression)) {
            throw new OpenGateException(code, message);
        }
    }
}
